<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/9 0009
 * Time: 17:00
 */

namespace Cohuna\Models;

use Phalcon\Di;

/**
 * 用户角色
 * @package Cohuna\Models
 */
class CohunaPermissionRole extends ModelBase
{
    public $role_id;
    public $role_name;
    public $resource_list;
    public $role_state;
    public $create_time;
    public $update_time;
    public $create_id;
    public $update_id;

    public function initialize()
    {
        parent::initialize();
    }

    public function getSource()
    {
        return Di::getDefault()->getShared('config')->database->default->prefix . 'permission_role';
    }

    public function beforeSave()
    {
        if(empty($this->resource_list) === false && is_array($this->resource_list)){
            $this->resource_list = implode(',',$this->resource_list);
        }
    }
    public function afterFetch()
    {
        if(empty($this->resource_list) === false && is_string($this->resource_list)){
            $this->resource_list = explode(',',$this->resource_list);
        }else{
            $this->resource_list = array();
        }
    }

    public function afterSave()
    {
        if(empty($this->resource_list) === false && is_string($this->resource_list)){
            $this->resource_list = explode(',',$this->resource_list);
        }
    }
}